{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.8.2 64-bit ('pinyintest')",
   "metadata": {
    "interpreter": {
     "hash": "39683e335443841a3fc148a11d1a35cae402287bab619c4f33f50b153809fdeb"
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 包的导入\n",
    "from xpinyin import Pinyin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'ye-fu-tian'"
      ]
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "# 中文名转拼音\n",
    "p = Pinyin()\n",
    "result1 = p.get_pinyin('叶伏天')\n",
    "result1"
   ]
  },
  {
   "source": [
    "# 显示声调\n",
    "result2 = p.get_pinyin('叶伏天', tone_marks='marks')\n",
    "result2"
   ],
   "cell_type": "code",
   "metadata": {},
   "execution_count": 3,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'yè-fú-tiān'"
      ]
     },
     "metadata": {},
     "execution_count": 3
    }
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'Ye Futian'"
      ]
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "# 将姓和名分开\n",
    "s = result1.split('-')\n",
    "result3 = s[0].capitalize() + ' ' + ''.join(s[1:]).capitalize()\n",
    "result3"
   ]
  }
 ]
}